/*
 * @lc app=leetcode.cn id=476 lang=rust
 *
 * [476] 数字的补数
 */

// @lc code=start
impl Solution {
    pub fn find_complement(num: i32) -> i32 {
        let mut tmp = 0;
        {
            let mut num = num;
            while num != 0{
                num >>= 1;
                tmp <<= 1;
                tmp |= 1;
            }
        }
        return !num & tmp;
    }
}
// @lc code=end

